package com.howie.parnote.web;


import com.howie.parnote.constant.RespMessageConstant;
import com.howie.parnote.service.*;
import com.howie.parnote.util.LogUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;


/**
 * <p>Title: parnote</p>
 * <p>
 * Description: parnote
 * </p>
 *
 * @author huangyan
 *         Created by HY on 2014/12/16 0016.
 * @version v1.0.0
 */
public abstract class ParnoteBaseController {

	protected Logger logger = LogUtil.getLogger(this.getClass());

	@Autowired
	protected RoleService roleService;
	@Autowired
	protected LocationService locationService;
	@Autowired
	protected IncidentService incidentService;
	@Autowired
	protected SharerService sharerService;
	@Autowired
	protected NoteService noteService;

	protected String respMsg;

	protected void setRespMsg(RespMessageConstant respConstant) {
		this.respMsg = respConstant.getMessage();
	}

	protected String successResponse() {
		return "{\"success\": true}";
	}

	/**
	 * response text to alert
	 *
	 * @param msg The differences are the " between the parameter msg
	 * @return
	 */
	protected String successResponse(String msg) {
		return "{\"success\": true,\"msg\":\"" + msg + "\"}";
	}

	/**
	 * ajax response json object
	 */
	protected String failResponse() {
		return "{\"success\": false, \"msg\":\"" + respMsg + "\"}";
	}

	protected String failResponse(RespMessageConstant message) {
		return "{\"success\": false, \"msg\":\"" + message.getMessage() + "\"}";
	}

	/**
	 * response some data structure,don't need the " symbol
	 *
	 * @param msg
	 * @return
	 */
	protected String jsonDataResponse(String msg) {
		return "{\"success\": true,\"msg\":" + msg + "}";
	}

	/**
	 * 表单数据绑定方法
	 *
	 * @param binder
	 */
	@InitBinder
	protected void initBinder(WebDataBinder binder) {
	}
}
